﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameEngine.Managers.IManagers;
using GameEngine.Entities;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using GameEngine.Scenes;

namespace GameEngine.Managers.ConcreteManagers
{
    public class RenderManager : IRenderManager
    {
        private SpriteBatch spriteBatch;
        private Game game;

        public RenderManager(Game game)
        {
            this.game = game;
            this.spriteBatch = new SpriteBatch(game.GraphicsDevice);
        }

        public void Draw(Microsoft.Xna.Framework.GameTime gameTime, List<Scene> sceneList)
        {
            foreach (Scene drawScene in sceneList)
            {
                if (drawScene == null)
                    continue;

                drawScene.Draw(spriteBatch, gameTime);

                if (drawScene.CollisionMap == null)
                    continue;

                List<Layer2D> layers = drawScene.Layers;
                Rectangle backgroundRectangle = new Rectangle(0, 0,
                    drawScene.CollisionMap.Width,
                    drawScene.CollisionMap.Height);

                foreach (Layer2D layer in layers)
                {
                    layer.Draw(spriteBatch, gameTime, backgroundRectangle);
                    foreach (AbstractEntity entity in layer.SceneObjects)
                    {
                        entity.Draw(spriteBatch, gameTime);
                    }
                }
            }
        }
    }
}